<template>
	<view>
		<view class="mask" @touchmove.stop="" v-show="show" @click="clased()"></view>

		<view class="work-record" @click.stop="" @touchmove.stop=""
			:style="show ? 'transform: translateY(0rpx);' : 'transform: translateY(1000rpx);'">
			<view class="line" @click="clased()"><text></text></view>
			<view class="content">
				<view class="content_title">{{ popupsTitle }}</view>

				<view class="tips">申诉原因<text style="color:red">*</text></view>
				<view class="notice" :style="{ borderColor: showToast ? '#E02020' : '#e9e9e9' }">
					<textarea type="textarea" v-model="remark" height="108rpx" placeholder="请输入.." @input="inputRemark"
						placeholder-class="textare" style="font-size: 28rpx;height:108rpx;" maxlength="300" />
					<view class="length">{{ remark.length + '/300' }}</view>
				</view>
				<view v-if="showToast" style="color: #E02020;">请填写申诉原因</view>

				<view class="tips">添加图片/视频</view>
				<view class="imgBox">
					<imageDragSort max="9" :list="imgUrl" tips="上传图片" @changeList="changeImg">
					</imageDragSort>
				</view>
				<view class="save"><button hover-class="none" @click="handleSave">提交</button></view>
			</view>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
import { submitAppealReason } from '@/apis/appeal.js';
import imageDragSort from '@/components/image-drag-sort/img-and-video.vue';

export default {
	props: {
		show: {
			type: Boolean,
			default: false
		},
		popupsTitle: {
			type: String,
			default: '添加申诉原因'
		}		
	},
	components: {
		imageDragSort
	},
	data() {
		return {
			title: '保养记录',
			suffix: '',
			// 历史记录
			checkHistory: {
				files: {},
				records: {},
				remarks: {}
			},
			// 图片或视频
			imgUrl: [],
			// 描述
			remark: '',
			// 数据记录
			record: '',
			// 模型 modelType 1签到模型，2签退模型 空不使用模型 
			modelType: '',
			// 判断当前小程序环境 ios/android
			platform: uni.getSystemInfoSync().platform,
			showToast: false,
			appealId: "",
		};
	},
	watch: {},
	created() { },
	beforeDestroy() {
		uni.$off('uploadImg');
	},
	computed: {
		...mapState('user', ['userinfo']),
	},
	methods: {
		initData() {

		},
		changeImg(imgArr = []) {
			this.imgUrl = imgArr;
		},
		clased() {
			this.showToast = false;
			this.appealId = "";
			this.imgUrl = [];
			this.remark = "";
			this.$emit('closed', false);
		},
		// 预览
		preViewFile(item, index) {
			this.$previewMedia({
				sources: this.imgUrl,
				current: index
			});
		},
		// 睡眠一会 time 毫秒
		timeSleep(time = 0) {
			return new Promise((resolve) => {
				setTimeout(() => {
					resolve();
				}, time);
			});
		},

		removeFile(idx) {
			this.imgUrl.splice(idx, 1);
			this.$forceUpdate();
		},
		inputRemark() {
			if (this.remark) {
				this.showToast = false;
			}
		},
		handleSave() {
			let appealImg = this.imgUrl;
			let appealDesc = this.remark || '';
			uni.showLoading({
				title: '保存中',
				mask: true
			});
			if (!appealDesc) {
				this.showToast = true;
				return uni.showToast({ title: '请输入申诉原因', icon: 'none' });
			}
			submitAppealReason({
				appealImg,
				appealDesc,
				id: this.appealId,
			}).then(res => {
				this.appealId = "";
				this.imgUrl = [];
				this.remark = "";
				uni.hideLoading();
				this.$emit('submit');
			})
		},

	}
};
</script>

<style lang="scss" scoped>
.mask {
	width: 100%;
	height: 100vh;
	position: fixed;
	top: 0rpx;
	left: 0rpx;
	z-index: 120;
	background-color: $uni-bg-color-mask;
}

.work-record {
	background-color: #fff;
	padding: 20rpx 40rpx 32rpx 40rpx;
	border-radius: 8rpx 8rpx 0rpx 0rpx;
	box-shadow: 0rpx -4rpx 12rpx 0rpx rgba(0, 0, 0, 0.12);
	position: fixed;
	z-index: 121;
	bottom: 0;
	transition: 0.4s all;
	transform: translateY(1000rpx);

	.line {
		margin-bottom: 18rpx;
		display: flex;
		justify-content: center;

		text {
			width: 64rpx;
			height: 10rpx;
			background: #d8d8d8;
			border-radius: 6rpx;
		}
	}

	.content {
		width: 100%;

		.content_title {
			width: 100%;
			font-size: 32rpx;
			font-weight: bold;
			color: #000;
		}

		.tips {
			display: flex;
			color: #000;
			align-items: center;
			margin-bottom: 16rpx;
			margin-top: 20rpx;

			image {
				width: 28rpx;
				height: 28rpx;
				margin-right: 6rpx;
			}
		}

		.imgBox {
			display: flex;
			flex-wrap: wrap;
			width: calc(100%);

			&-item {
				width: 112rpx;
				height: 112rpx;
				background: #f7f7f8;
				margin-right: 20rpx;
				margin-bottom: 20rpx;
				position: relative;

				image {
					width: 100%;
					height: 100%;
				}

				.text {
					position: absolute;
					display: block;
					width: 32rpx;
					height: 32rpx;
					top: -10rpx;
					font-weight: bold;
					font-size: 34rpx;
					line-height: 25rpx;
					border-radius: 50%;
					right: -7rpx;
					text-align: center;
					color: #fff;
					z-index: 9;
					background: #ababab;
				}

				.ai-result {
					position: absolute;
					bottom: 0;
					left: 0;
					display: flex;
					align-items: center;
					justify-content: center;
					text-align: center;
					width: 112rpx;
					height: 32rpx;
					color: #fff;
					font-size: 22rpx;
					padding: 0;
					vertical-align: unset;
					font-weight: normal;

					&-ico {
						width: 21rpx;
						height: 21rpx;
						margin-right: 4rpx;
					}
				}

				.gre {
					background-color: #68CA00;
				}

				.org {
					background-color: #FF7505;
				}

				.red {
					background-color: #E02020;
				}
			}

			&-add {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				background-color: #fff;
				// border: 1rpx solid #e0e0e0;
				background-color: #f7f7f8;
				flex-wrap: wrap;
				color: $theme-color;
				font-size: 24rpx;

				image {
					width: 40rpx;
					height: 40rpx;
				}

				view {
					width: 100%;
					text-align: center;
				}
			}
		}

		.notice {
			width: 94%;
			padding: 20rpx;
			height: 108rpx;
			border: 2rpx solid #e9e9e9;
			border-radius: 4rpx;
			position: relative;
			padding-bottom: 30rpx;
		}

		textarea {
			font-size: 28rpx;
			width: 100%;
			height: 108rpx;
		}

		.length {
			text-align: right;
			color: #ccc;
			position: absolute;
			right: 10rpx;
			font-size: 2;
			font-size: 24rpx;
			bottom: 5rpx;
		}

		.records {
			display: flex;
			align-items: center;
			font-size: 28rpx;
			justify-content: flex-start;

			input {
				width: 316rpx;
				/* height: 72rpx; */
				border: 2rpx solid #e9e9e9;
				border-radius: 4rpx;
				/* line-height: 72rpx; */
				padding: 12rpx;
			}

			text {
				color: #666666;
				margin-left: 10rpx;
			}
		}
	}

	.save {
		flex: 1;
		display: flex;
		justify-content: center;
		margin-top: 20rpx;

		button {
			display: flex;
			width: 670rpx;
			height: 70rpx;
			// background: #0091ff;
			border-radius: 8rpx;
			// color: #fff;
			justify-content: center;
			align-items: center;
		}
	}
}
</style>
